﻿/**
作者：魏铁雷
时间：209-11-23
功能：实现栏目修改
**/
var ModelId = "";
var ModelPid = "";
var rd_flg = "1"; //单选按钮默认是1启用状态
var Obj = new Object();
var page;
var UploadActionPath = SBasePath + "/action/upload/";
var ContactUsImageArray = new Array();
var ImageArr = new Array('.jpg', '.gif', '.png', '.bmp','.swf','.rar'); //形象图片类型
var UploadType = 1; //1:缩略图2:原图
var _mDebug = false; //用于调试显示上传显示部分

function ShowMain() {
    page = request("page");
    ModelPid = request("ModelPid");
    ModelId = request("modelid");
    GetModel();
}
//获取"信息"
function GetModel() {
    var url = encodeURI(SBasePath + '/action/ModelManage/GetModel.aspx');
    var pars = encodeURI('?id=' + ModelId);
    var myAjax = new Ajax.Request(url, { method: 'get', parameters: pars, onComplete: sGetModel, onFailure: fGetModel });
}
//获取"信息"成功
function sGetModel(o) {
    Obj = MapModel(o);

    ShowContent();
}

//获取"信息"成功失败
function fGetModel(o) {

}

function ShowContent() {
    var str = "";
    str += '<form id="formModel">';
    str += '<input type="hidden" id="mid" name="mid" value="' + ModelId + '"/>';
    str += '<input type="hidden" id="rd" name="rd" value="' + rd_flg + '"/>';
    str += '<input type="hidden" id="hidImgUrl" name="hidImgUrl"/>';
    str += '<input type="hidden" id="ImgUrl" name="ImgUrl" value="'+Obj.ImgUrl+'"/>';

    
        str+='<table width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">';
        str+='<tr>';
        str+='    <td height="30">';
        str+='        <table width="100%" border="0" cellspacing="0" cellpadding="0">';
        str+='            <tr>';
        str+='                <td width="15" height="30" class="tab03">';
        str+='                </td>';
        str+='                <td class="tab05">';
        str+='                    <div class="title1" style="padding-top: 2px">';
        str+='                        <img src="../../img/1.gif" height="20" width="19" />修改栏目</div>';
        str+='                </td>';
        str+='                <td width="14" class="tab07"></td>';
        str+='            </tr>';
        str+='        </table>';
        str+='    </td>';
        str+='</tr>';
        str+='<tr>';
        str+='    <td>';
        str+='        <table width="100%" border="0" cellspacing="0" cellpadding="0">';
        str+='            <tr>';
        str+='                <td width="9" class="tab12"></td>';
        str+='                <td bgcolor="#f3ffe3">';
        str+='                    <table width="100%" border="0" cellspacing="0" cellpadding="0">';
        str+='                        <tr>';
        str+='                            <td class="k_hui">';
        str+='                                <table width="97%" border="0" cellspacing="0" cellpadding="0" align="center">';
        str+= '                                    <tr height="38">';
        str+='                                        <td height="30" width="15%" style="padding-left: 5px">';
        str += '                                            栏目名称：';
        str+='                                        </td>';
        str+='                                        <td width="80%">';
        str += '                                            <input type="text" name="lmmc" id="lmmc" value="' + Obj.ModelName + '" class="wbk" />';
        str+='                                        </td>';
        str+='                                    </tr>';
        str+= '                                    <tr height="38">';
        str+='                                        <td height="30" width="12%" style="padding-left: 5px">';
        str += '                                            英文名称：';
        str+='                                        </td>';
        str+='                                        <td widht="25%">';
        str += '                                            <input type="text" name="ywmc" id="ywmc" value="' + Obj.MEnglishName + '" class="wbk"/>';
        str+='                                        </td>';
        str+='                                    </tr>';
        str+= '                                    <tr height="38">';
        str+='                                        <td height="30" width="12%" style="padding-left: 5px">';
        str += '                                            排序编号：';
        str+='                                        </td>';
        str+='                                        <td widht="25%">';
        str += '                                            <input type="text" name="order" id="order" value="'+Obj.OrderId+'" class="wbk"/>';
        str+='                                        </td>';
        str += '                                   </tr>';
        str += '                                    <tr height="38">';
        str += '                                        <td height="30" width="12%" style="padding-left: 5px">';
        str += '                                            模块路径：';
        str += '                                        </td>';
        str += '                                        <td widht="25%">';
        str += '                                            <input type="text" name="ModelUrl" id="ModelUrl" value="' + Obj.ModelPath + '" class="wbk"/>';
        str += '                                        </td>';
        str += '                                   </tr>';
        str += '                                    <tr height="38">';
        str += '                                        <td height="30" width="12%" style="padding-left: 5px">';
        str += '                                            链接：';
        str += '                                        </td>';
        str += '                                        <td widht="25%">';
        str += '                                            <input type="text" name="HttpUrl" id="HttpUrl" value="'+Obj.HttpUrl+'" class="wbk"/>';
        str += '                                        </td>';
        str += '                                   </tr>';
        str+= '                                    <tr height="38">';
        str+='                                        <td height="30" width="12%" style="padding-left: 5px">';
        str += '                                            启用状态：';
        str+='                                        </td>';
        str += '                                        <td widht="25%">';
        if(Obj.ZT==1){
        str += '                                            <input type="radio" name="zt"  checked=true id="qy" value=""/>启用<input type="radio" name="zt" id="jy" value=""/>禁用';
    } else {
    str += '                                            <input type="radio" name="zt"   id="qy" value=""/>启用<input type="radio" name="zt" id="jy" checked=true value=""/>禁用';
        }
        str+='                                        </td>';
        str += '                                   </tr>';
        
        str += '                                    <tr height="38">';
        str += '                                        <td height="30" width="12%" style="padding-left: 5px">';
        str += '                                            图片格式：';
        str += '                                        </td>';
        str += '                                        <td widht="80%">';
        if (Obj.imgwh == "0") {
            str += '                                        <input type="radio" name="imgwh"   id="small" checked="true" value="0"/>小图:240*60(宽*高)<input type="radio" name="imgwh" id="big" value="1"/>大图:740*110(宽*高)<font color="red">【请上传正确大小图片】</font> <a href="' + WebBasePath + Obj.ImgUrl + '"  target="_blank">图片预览</a>';
        } else if (Obj.imgwh == "1") {
        str += '                                            <input type="radio" name="imgwh"   id="small"  value="0"/>小图:240*60(宽*高)<input type="radio" checked="true" name="imgwh" id="big" value="1"/>大图:740*110(宽*高)<font color="red">【请上传正确大小图片】</font><a href="' + WebBasePath + Obj.ImgUrl + '" target="_blank">图片预览</a>';
        } else {
        str += '                                            <input type="radio" name="imgwh"   id="small"  value="0"/>小图:240*60(宽*高)<input type="radio" name="imgwh" id="big" value="1"/>大图:740*110(宽*高)<font color="red">【请上传正确大小图片】</font>';
 
        }
        
        str += '                                        </td>';
        str += '                                   </tr>';
        
       str += '</form>';
        str += '                                    <tr height="38">';
        str += '                                        <td height="30" width="12%" style="padding-left: 5px">';
        str += '                                            上传图片：';
        str += '                                        </td>';
        str += '                                        <td widht="25%">';
        str += '                <form name="myform" id="myform" action="' + UploadActionPath + 'UploadCommResult.aspx"; method="post" enctype="multipart/form-data" target="targethidenfram">';
        str += '                <input type="file" value="" name="file1" id="file1" class="input2">';
        str += '                <input onclick="StartUpload(\'myform\',\'1\');" type="button" name="SubmitButton" id="SubmitButton"   style="height:23"  value="上传">';
        str += '                <div id="progressout"></div>';
        str += '                <div id="ShrinImageDiv"></div>';
        str += '                 </form>'; 
        str += '                                        </td>';
        str += '                                   </tr>';
        str += '                                    <tr height="38">';
        str+='                                        <td colspan="2" style="padding-left: 25px" height="30">';
        str += '                                             <input name="提交" type="button" class="bg_g" style="height: 22px; width: 60px; border: solid 1px #cadcb2;"value="提交" onclick="Edit_Model()" />';
        str+='                                            &nbsp;&nbsp;<input name="重置" type="reset" class="bg_g" style="height: 22px; width: 60px;border: solid 1px #cadcb2;" value="重置" />';
        str+='                                        </td>';
        str+='                                        <td width="52%" class="zw">';
        str+='                                        </td>';
        str+='                                    </tr>';
        str+='                                </table>';
        str+='                             </td>';
        str+='                        </tr>';
        str+='                    </table>';
        str+='                </td>';
        str+='                <td width="9" class="tab16">';
        str+='                </td>';
        str+='            </tr>';
        str+='        </table>';
        str+='    </td>';
        str+='</tr>';
        str+='<tr>';
        str+='    <td height="29">';
        str+='        <table width="100%" border="0" cellspacing="0" cellpadding="0">';
        str+='            <tr>';
        str+='                <td width="15" height="29" class="tab20">';
        str+='                </td>';
        str+='                <td class="tab21">';
        str+='                    &nbsp;';
        str+='                </td>';
        str+='                <td width="14" class="tab22">';
        str+='                </td>';
        str+='            </tr>';
        str+='        </table>';
        str+='    </td>';
        str+='</tr>';
        str += '</table>';

        if (_mDebug) {
            str += '  <iframe id="targethidenfram" name="targethidenfram" frameborder="0" height="200" width="400" visible="false"></iframe>';
        }
        else {
            str += '  <iframe id="targethidenfram" name="targethidenfram" frameborder="0" height="0" width="0" visible="false"></iframe>';
        }
        $("ModelEdit").innerHTML=str;
    }
    //提交
    var Edit_Model = function() {
        if (CheckEditForm()) {
            var url = encodeURI(SBasePath + '/action/ModelManage/EditModel.aspx');
            var myAjax = new Ajax.Request(url, { method: 'post', parameters: Form.serialize("formModel"), onComplete: sEditModels, onFailure: fEditModels });
        }
    };

    var sEditModels = function(o) {
        var root = o.responseXML.documentElement;
        var flag = GetXmlData(root, "Value");
        if (flag == "true") {
            window.top.frames["Content"].location.href = SBasePath + '/htm/ModelManage/ModelList.htm?ModelId=' + ModelPid + '&page=' + page;

        } else {
        MsgDlg("修改失败！")

        }
    };

    var fEditModels = function(o) {

    };

    var CheckEditForm = function() {

        var fobj = $("formModel");

        if (fobj.lmmc.value == "") {
            alert("栏目名称不能为空");
            fobj.lmmc.focus();
            return false;
        }

        if (fobj.ywmc.value == "") {

            alert("英文名称不能为空");
            fobj.ywmc.focus();
            return false;
        }
        if (fobj.order.value == "") {

            alert("编号不能为空");
            fobj.order.focus();
            return false;
        } 
        if (fobj.ModelUrl.value == "") {

            alert("路径不能为空");
            fobj.ModelUrl.focus();
            return false;
        }
        if (fobj.jy.checked == true) {
            rd_flg = "0";
            fobj.rd.value = rd_flg;

        }
        return true;
    };


    /*-------------------------------------------以下关于上传-------------------------------------------------*/
    var progressWindow;
    function StartUpload(formObj, Type)//开始上传
    {
        UploadType = Type;
        if (chkGroupImageFileValid()) {
            if (typeof (formObj) == "string")
                formObj = document.getElementById(formObj);
            //Show Cancel button
            var CancelButton = document.getElementById("CancelButton");
            if (CancelButton && PowUploadCanCancel())
                CancelButton.style.visibility = "visible";

            var uniqueID = Math.floor(Math.random() * 10000000) + (new Date()).getTime() % 1000000000;
            progressWindow = ShowProgressInFrame(uniqueID, UploadActionPath + 'Progress.aspx', 400, 200); //显示进度条	

            thePos = formObj.action.indexOf("UploadID");
            //Cut earlier added UploadID.
            if (thePos >= 1)
                formObj.action = formObj.action.substring(0, thePos - 1);
            if (formObj.action.indexOf("?") == -1)
                formObj.action += '?UploadID=' + uniqueID
            else
                formObj.action += '&UploadID=' + uniqueID;
            formObj.submit();
            return true;
        }
    }

    //Function ShowProgressInNewWindow() to show progress bar in new window.
    function ShowProgressInFrame(uniqueID, URL, width, height) {
        var l = (screen.width - width) / 2;
        var t = (screen.height - height) / 2;
        //	var winParams = 'toolbar=no,scrollbars=no,location=no,status=no,menubar=no,resizable=yes';
        //	winParams += ',width=' + width + ',height=' + height + ',left=' + l + ',top=' + t;
        var fullURL = URL;
        thePos = fullURL.indexOf("UploadID");
        //Cut earlier added UploadID.
        if (thePos >= 1)
            fullURL = fullURL.substring(0, thePos - 1);
        if (URL.indexOf("?") == -1)
            fullURL += '?UploadID=' + uniqueID;
        else
            fullURL += '&UploadID=' + uniqueID;
        $("progressout").innerHTML = '<iframe id="progressframe" name="' + uniqueID + '" frameborder="0" height="' + height + '" width="' + width + '" visible="true" src="' + fullURL + '" SCROLLING="no"></iframe>';
        //var newProgressWindow = window.open(fullURL, uniqueID, winParams);
        var newProgressWindow = $("progressframe");
        return newProgressWindow;
    }

    //上传成功后的回调函数
    function UploadCommplete(fobjs) {

        var str = "";
        var filename = "";
        if (fobjs != null) {
            for (var i = 0; i < fobjs.length; i++) {
                str += fobjs[i].FileName + "<br>";
                if (fobjs[i].FileName != "") {
                    filename = fobjs[i].FileName;
                }
            }
        }

        $("progressout").style.display = "none";
        if (UploadType == 1) {
            //  $("ShrinImageDiv").innerHTML = '<img src="/web' + filename + '" width="300" height="300" />';
            $("ShrinImageDiv").innerHTML = '<a href="/web' + filename + '" target="_blank" >上传成功</a>';
            $("hidImgUrl").value = filename;
        }
        else {
            ContactUsImageArray[ContactUsImageArray.length++] = filename;
            ShowContactUsImage(ContactUsImageArray);
        }


    }

    //检查形象图片的合法性
    function chkGroupImageFileValid() {
        var objs = null;
        if (UploadType == 1) {

            objs = $("file1");
        }
        else {
            objs = $("file2");
        }

        if (objs.value == "") {
            MsgDlg("您还没有选择任何文件!");
            return false;
        }
        else {
            var name = objs.value;
            name = name.substring(name.lastIndexOf('.'));
            for (var i = 0; i < ImageArr.length; i++) {
                if (name.toLowerCase() == ImageArr[i]) {
                    return true;
                }
            }
            MsgDlg("您所选择的文件类型不对!");
            return false;
        }
    }

    //--------------------------------------

    function OpenWin(url) {
        var str = "";

        str += '<table border="1" cellspacing="0" cellpadding="0"  style="border-collapse: seperate" bordercolordark="#FFFFFF" width="96%">';
        str += '         <tr>';
        str += '             <td align="center" style="height: 27px; width: 80px;"><img src="'+url+'" border="0"></img></td>';
       
        str += '         </tr>';
      
        str += '</table>';

        WindowDlg("ShowContentDiv", str, "图片预览", 380, 200);
    }